<?php

/**
 * 物流对账单 ajax类
 * @package  ajax
 * @subpackage  backend 
 * @create by allen.qiang
 */

quanli_require('module/base/wmsHandler.class.php');

class ajax_logistics {

    public function execute() {

        if (isset($_REQUEST['operFlg']) && $_REQUEST['operFlg'] > 0) {

            switch($_REQUEST['operFlg']) {

                case 1:
                    $this->logisticsList();//物流对账单列表
                    break;

            }

        } else {

            $this->toReturn('参数错误');

        }

    }

    /**
     * 返回信息
     * @param string $message
     * @param int $code
     * @param mixed $data
     */
    private function toReturn( $message, $code = 400, $data = '' ) {

        die( json_encode( array( 'code' => $code, 'message' => $message, 'data' => $data ) ) );

    }

    private function logisticsList(){

        global $G_PGLOB;

        $wmsHandler = new wmsHandler($G_PGLOB->DBCA);

        $arg_array = $_REQUEST;

        //查询包裹表
        $package = $wmsHandler->searchPackageInfo($arg_array,2);

        //查询包裹订单
        $result = $wmsHandler->searchPackageBill($package);

        //查询结果
        $result_array = array(
            'page'  => $_REQUEST['page'],
            'total' => $arg_array['count'],
            'rows'  => array()
        );

        if($package){

            foreach($result as $val) {

                $result_array['rows'][] = array(
                    'id'   => $val['package_no'],
                    'cell' => array(
                        $val['logistics_name'],
                        $val['package_no'],
                        $val['storeName'],
                        isset($val['billstr'])?$val['billstr']:'',
                        $val['goods_weight'],
                        $val['freight_fee'],
                        $val['freight_bill_no'],
                        $val['dispatch_time'],
                        $val['send_region_name'],
                        $val['deliver_name'],
                        $val['deliver_mobile']

                    )
                );
            }

        }

        echo json_encode($result_array);
    }

}